package com.ls.bpmn.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ls.bpmn.entity.Category;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ls.bpmn.vo.ProcessDefinitionVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author ls
 * @since 2025-04-21
 */
public interface CategoryMapper extends BaseMapper<Category> {

    @Select({
            "<script>",
            "select c.name,p.id_,p.key_,p.name_,p.version_ ",
            "from bpmn_category_process cp ",
            "inner join act_re_procdef p on p.KEY_ = cp.definition_key and p.id_ =cp.definition_id ",
            "inner join bpmn_category c on cp.category_id = c.id ",
            "<when test = 'categoryId != null'> where cp.category_id = #{categoryId} </when>",
            "</script>"
    })
    @Results({
            @Result(column = "key_", property = "key"),
            @Result(column = "name_", property = "name"),
            @Result(column = "id_", property = "id"),
            @Result(column = "name", property = "category"),
            @Result(column = "version_", property = "version")
    })
    List<ProcessDefinitionVO> selectCategoryDefinition(Page<ProcessDefinitionVO> page, @Param("categoryId") Integer categoryId);

}
